package org.example.configdemo.Controller;

import jakarta.annotation.PostConstruct;
import org.example.configdemo.Model.Student;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class YmlController {
//    取值
//    @Value("${myKey}")
//    private String myKey;
//    @Value("${server.port}")
//    private Integer serverPort;
//
////    初始化方法
//    @PostConstruct
//    public void readValue(){
////        System.out.println("myKey");
//        System.out.println("=====================");
//        System.out.println(serverPort);
//    }

    @Value("${server.port}")
    private Integer serverPort;

    @RequestMapping("/readValue")
    public Integer readValue1(){
        return serverPort;
    }

    @Autowired
    private Student student;

    @PostConstruct
    public void readValue2(){
        System.out.println(student);
    }
}
